package com.yugao.fintech.draper.gateway.configure;

import com.yugao.fintech.draper.gateway.handler.AjImageCodeCheckHandler;
import com.yugao.fintech.draper.gateway.handler.AjImageCodeCreateHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

/**
 * 验证码路由
 */
@Configuration
public class CaptchaConfiguration {

    @Bean
    public RouterFunction<ServerResponse> captchaRouterFunction(AjImageCodeCreateHandler ajImageCodeCreateHandler,
                                                                AjImageCodeCheckHandler ajImageCodeCheckHandler) {
        return RouterFunctions
                .route(RequestPredicates.path("/code").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),
                        ajImageCodeCreateHandler)
                .andRoute(RequestPredicates.POST("/code/check").and(RequestPredicates.accept(MediaType.ALL)),
                        ajImageCodeCheckHandler);
    }
}
